package aeolus.wind.spider.biz.dataobject;

import aeolus.wind.spider.biz.constants.Constants;

import com.sleepycat.persist.model.Entity;
import com.sleepycat.persist.model.PrimaryKey;
import com.sleepycat.persist.model.Relationship;
import com.sleepycat.persist.model.SecondaryKey;

@Entity
public class Ability {

    @PrimaryKey
    private String id;
    @SecondaryKey(relate = Relationship.MANY_TO_ONE)
    private String name;
    private String description;
    /**
     * 能力所属人
     */
    @SecondaryKey(relate = Relationship.MANY_TO_ONE)
    private String ownIdentityName;

    public Ability() {
    }

    public Ability(String name, String description, String ownIdentityName) {
        this.name = name;
        this.description = description;
        this.ownIdentityName = ownIdentityName;
    }

    public String getId() {
        setId();
        return id;
    }

    public void setId() {
        id = new StringBuffer().append(ownIdentityName).append(Constants.PK_SEP).append(name).toString();
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getOwnIdentityName() {
        return ownIdentityName;
    }

    public void setOwnIdentityName(String ownIdentityName) {
        this.ownIdentityName = ownIdentityName;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;
        if (!(obj instanceof Ability)) return false;
        if (((Ability) obj).id.equals(id)) return true;
        return false;
    }

    @Override
    public int hashCode() {
        return id.hashCode();
    }

}
